package com.fancy.common.exception;

import java.util.Locale;

import com.fancy.common.constant.ResponseConstants;
import com.fancy.common.constant.i18n.BaseI18n;
import com.fancy.common.utils.SpringUtil;

/**
 * 异常基类
 * 
 * @author xinfeng.hu 2013-3-13下午12:15:34
 * @version 1.0.0
 * @category 杭州广桥网络技术有限公司(商业先知)
 */
public class BaseException extends RuntimeException {

	/**
	 * 序列化版本号
	 */
	private static final long serialVersionUID = 951860079180937477L;

	/**
	 * 错误码
	 */
	private final int errorCode;

	/**
	 * 国际化异常信息code
	 */
	private final BaseI18n messageCode;

	public BaseException(final String message) {
		super(message);
		this.errorCode = ResponseConstants.SC_INTERNAL_SERVER_ERROR;
		this.messageCode = null;
	}
	
	public BaseException(final int errorCode) {
		this.errorCode = errorCode;
		this.messageCode = null;
	}

	public BaseException(final int errorCode, final BaseI18n messageCode, final Object... arg) {
		super(SpringUtil.getMessage(messageCode, arg));
		this.errorCode = errorCode;
		this.messageCode = messageCode;
	}

	public BaseException(final int errorCode, final BaseI18n messageCode, final Locale locale, final Object... arg) {
		super(SpringUtil.getMessage(messageCode, locale, arg));
		this.errorCode = errorCode;
		this.messageCode = messageCode;
	}

	public int getErrorCode() {
		return this.errorCode;
	}

	public BaseI18n getMessageCode() {
		return messageCode;
	}
}
